package com.yisu.expressway.trafficViolation;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.yisu.expressway.R;
import com.yisu.expressway.activity.BaseActivity;
import com.yisu.expressway.adapter.CarIllegalRecordAdapter;
import com.yisu.expressway.model.CarIllegalInfo;
import com.yisu.expressway.ui.recyclerview.DividerListItemDecoration;

import java.util.ArrayList;

import butterknife.Bind;

public class CarIllegalRecordActivity extends BaseActivity {

    @Bind(R.id.rv_record_list)
    protected RecyclerView mRv_list;
    @Bind(R.id.tv_car_number)
    protected TextView mCarNumber;

    private final static String RECORD_LIST = "record_list";
    private final static String CAR_NUMBER = "car_number";
    ArrayList<CarIllegalInfo> mRecordList;
    private String carNumber;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_car_illegal_record);
        initView(getIntent());
    }

    private void initView(Intent intent){
        setTitle(R.string.car_illegal_record);
        if(intent != null) {
            mRecordList = (ArrayList<CarIllegalInfo>)intent.getSerializableExtra(RECORD_LIST);
            carNumber = intent.getStringExtra(CAR_NUMBER);
            CarIllegalRecordAdapter mAdapter = new CarIllegalRecordAdapter(this, mRecordList);
            mRv_list.setLayoutManager(new LinearLayoutManager(this));
            mRv_list.addItemDecoration(new DividerListItemDecoration(this,LinearLayoutManager.VERTICAL,8,R.color.transparent));
            mRv_list.setAdapter(mAdapter);
            mCarNumber.setText(carNumber);
        }
    }

    public static void launch(Context context, ArrayList<CarIllegalInfo> list,String carNumber){
        Intent intent = new Intent(context,CarIllegalRecordActivity.class);
        intent.putExtra(RECORD_LIST,list);
        intent.putExtra(CAR_NUMBER,carNumber);
        context.startActivity(intent);
    }
}
